package com.qiangesoft.im.controller;

import com.qiangesoft.im.pojo.dto.ImGroupDTO;
import com.qiangesoft.im.pojo.dto.ImGroupMasterDTO;
import com.qiangesoft.im.pojo.vo.ImGroupInfoVO;
import com.qiangesoft.im.pojo.vo.ImGroupVO;
import com.qiangesoft.im.pojo.vo.ResultInfo;
import com.qiangesoft.im.service.IImGroupService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 群组 前端控制器
 * </p>
 *
 * @author qiangesoft
 * @date 2024-02-07
 */
@Api(tags = "群组")
@RestController
@RequestMapping("/im/group")
public class ImGroupController {

    @Autowired
    private IImGroupService groupService;

    @PostMapping
    @ApiOperation(value = "建群")
    public ResultInfo<Void> addGroup(@RequestBody ImGroupDTO groupDTO) {
        groupService.addGroup(groupDTO);
        return ResultInfo.ok();
    }

    @DeleteMapping("/{id}")
    @ApiOperation(value = "解散群")
    public ResultInfo<Void> removeGroup(@PathVariable Long id) {
        groupService.removeGroup(id);
        return ResultInfo.ok();
    }

    @PutMapping("/{id}")
    @ApiOperation(value = "编辑群")
    public ResultInfo<Void> updateGroup(@PathVariable Long id, @RequestBody ImGroupDTO groupDTO) {
        groupService.updateGroup(id, groupDTO);
        return ResultInfo.ok();
    }

    @GetMapping
    @ApiOperation(value = "群列表")
    public ResultInfo<List<ImGroupVO>> listGroup(String keyword) {
        return ResultInfo.ok(groupService.listGroup(keyword));
    }

    @GetMapping("/{id}")
    @ApiOperation(value = "群详情")
    public ResultInfo<ImGroupInfoVO> getGroupInfo(@PathVariable Long id) {
        return ResultInfo.ok(groupService.getGroupInfo(id));
    }

    @GetMapping("/updateMaster")
    @ApiOperation(value = "变更群主")
    public ResultInfo<Void> updateMaster(@RequestBody ImGroupMasterDTO groupMasterDTO) {
        groupService.updateMaster(groupMasterDTO);
        return ResultInfo.ok();
    }
}

